/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var req;
var deleteButton;

function deleteFriend(form) {
    var url = "DeleteFriend?friendId=" + escape(form.friendId.value);
    deleteButton = form.deleteButton;
    req = initRequest();
    req.open("GET", url, true);
    req.onreadystatechange = deleteFriend_callback;
    req.send(null);
}

function deleteFriend_callback() {
    if (req.readyState == 4 && req.status == 200) {
        deleteFriend_parseMessage(req.responseXML);
    }
}

function deleteFriend_parseMessage(responseXML) {
    if (responseXML == null) {
        //
    } else {
        // change here
        var message = responseXML.getElementsByTagName("message")[0];
        var toPrint = message.childNodes[0].nodeValue;
        if (toPrint.toString() == "success") {
            deleteButton.value = "Deleted";
            deleteButton.disabled = true;
            
            // update numberOfFriends at side bar
              var numOfFriends = parseInt($("numOfFriends").innerHTML);
            $("numOfFriends").innerHTML = numOfFriends - 1;
        } else {
            alert(message.childNodes[0].nodeValue);
        }
    }
}

